﻿using System.Collections.Generic;
using System.Data;
using Smatime.Web.DAO.SmatimeDatasetTableAdapters;
using Smatime.Web.Models;

namespace Smatime.Web.DAO
{
    public class ListStoreOfCompanyRepository :
        BaseRepository<ListStoreOfCompany, SmatimeDataset.StoreOfCompanyDataTable, StoreOfCompanyTableAdapter>
    {
        /// <summary>
        ///     Get Store today list
        /// </summary>
        /// <returns></returns>
        public IEnumerable<ListStoreOfCompany> GetListById(long id)
        {
            using (var adapter = new StoreOfCompanyTableAdapter())
            {
                using (var table = adapter.GetDataBy(id))
                {
                    var list = new List<ListStoreOfCompany>();
                    foreach (DataRow row in table.Rows)
                    {
                        var storeOfCompany = new ListStoreOfCompany();
                        storeOfCompany.FromDataRow(row);
                        list.Add(storeOfCompany);
                    }
                    return list;
                }
            }
        }

        /// <summary>
        ///     Return the company store by ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ListStoreOfCompany GetByStoreId(long id)
        {
            using (var adapter = new StoreOfCompanyTableAdapter())
            {
                var list = new List<ListStoreOfCompany>();
                using (var table = adapter.GetDataByStoreId(id))
                {
                    var row = table.Rows[0];
                    return (ListStoreOfCompany) (new ListStoreOfCompany().FromDataRow(row));
                }
            }
        }
    }
}